package cn.xscrum.vtsp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.vtsp.domain.VtspType;
import cn.xscrum.vtsp.service.IVtspTypeService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 活动类型Controller
 * 
 * @author xscrum
 * @date 2021-10-01
 */
@Controller
@RequestMapping("/vtsp/type")
public class VtspTypeController extends BaseController
{
    private String prefix = "vtsp/type";

    @Autowired
    private IVtspTypeService vtspTypeService;

    @RequiresPermissions("vtsp:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
	 * 查询活动类型列表
     */
    @RequiresPermissions("vtsp:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VtspType vtspType)
    {
        startPage();
        List<VtspType> list = vtspTypeService.selectVtspTypeList(vtspType);
        return getDataTable(list);
    }

    /**
	 * 导出活动类型列表
     */
    @RequiresPermissions("vtsp:type:export")
    @Log(title = "活动类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VtspType vtspType)
    {
        List<VtspType> list = vtspTypeService.selectVtspTypeList(vtspType);
        ExcelUtil<VtspType> util = new ExcelUtil<VtspType>(VtspType.class);
        return util.exportExcel(list, "type");
    }

    /**
	 * 新增活动类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存活动类型
     */
    @RequiresPermissions("vtsp:type:add")
    @Log(title = "活动类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VtspType vtspType)
    {
        System.out.println("请求了此方法");
        System.out.println("前端传来的参数 --------------" + vtspType);
        return toAjax(vtspTypeService.insertVtspType(vtspType));
    }

    /**
	 * 修改活动类型
     */
    @GetMapping("/edit/{typeId}")
    public String edit(@PathVariable("typeId") Long typeId, ModelMap mmap)
    {
        VtspType vtspType = vtspTypeService.selectVtspTypeById(typeId);
        mmap.put("vtspType", vtspType);
        return prefix + "/edit";
    }

    /**
	 * 修改保存活动类型
     */
    @RequiresPermissions("vtsp:type:edit")
    @Log(title = "活动类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VtspType vtspType)
    {
        System.out.println("请求了此方法");
        System.out.println("前端传来的参数 --------------" + vtspType);
        return toAjax(vtspTypeService.updateVtspType(vtspType));
    }

    /**
	 * 删除活动类型
     */
    @RequiresPermissions("vtsp:type:remove")
    @Log(title = "活动类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        System.out.println("请求了此方法");
        System.out.println("前端传来的参数 --------------" + ids);
        return toAjax(vtspTypeService.deleteVtspTypeByIds(ids));
    }
}
